﻿<!DOCTYPE html>

@{
    string cssActive = string.Empty;    

}

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="iRacer">

    <title>@ViewBag.Title</title>
    
    <link href="/Content/noke/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Content/noke/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="/Content/noke/css/animate.css" rel="stylesheet">
    @RenderSection("css", required: false)    
    <link href="/Content/noke/css/style.css" rel="stylesheet">
</head>
<body>
    
    <div id="wrapper">
        
<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="sidebar-collapse">
        <ul class="nav metismenu" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element"> <span>
                        <img alt="image" class="img-circle" src="/Content/noke/img/profile_small.jpg" />
                            </span>
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">Genshui Yang</strong>
                            </span> <span class="text-muted text-xs block">Art Programmer<b class="caret"></b></span> </span> </a>
                    <ul class="dropdown-menu animated fadeInRight m-t-xs">
                        <li><a href="profile.html">个人中心</a></li>
                        <li><a href="contacts.html">通讯录</a></li>
                        <li><a href="mailbox.html">设置</a></li>
                        <li class="divider"></li>
                        <li><a href="login.html">Logout</a></li>
                    </ul>
                </div>
                <div class="logo-element">
                    NE+
                </div>
            </li>

        </ul>
    </div>
</nav>


    <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
                <nav class="navbar navbar-static-top  " role="navigation" style="margin-bottom: 0">
                    
                    <div class="navbar-header">
                        <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
                    </div>
                    <ul class="nav navbar-top-links navbar-right">
                        <li>
                            <span class="m-r-sm text-muted welcome-message">Welcome to BENLAI Study.</span>
                        </li>
                        <li>
                            <a href="javascript:addApiDoc();"><i class="fa fa-plus"></i> 新增文档</a>
                        </li>
                        <li>
                            <a href="http://wowubuntu.com/markdown/basic.html"><i class="fa fa-codepen"></i> 学习Markdown</a>
                        </li>
                        <li>
                            <a href="/Home/"><i class="fa fa-university"></i> 返回</a>
                        </li>
                        <li>
                            <a href="login.html">
                                <i class="fa fa-sign-out"></i> Log out
                            </a>
                        </li>
                    </ul>
                </nav>


        </div>
            <div class="row wrapper border-bottom white-bg page-heading" style="padding-bottom:0;">

                @RenderSection("head", false)

            </div>

            <div class="wrapper wrapper-content" style="padding:5px;">
                
                @RenderBody()

            </div>

            <div class="footer">
                <div class="pull-right">
                    10GB of <strong>250GB</strong> Free.
                </div>
                <div>
                    <strong>Copyright</strong> Benlai &copy; 2014-2015
                </div>
            </div>

        </div>
    </div>



    
    <!-- Mainly scripts -->
    <script src="/Content/noke/js/jquery-2.1.1.js"></script>
    <script src="/Content/noke/js/bootstrap.min.js"></script>
    <script src="/Content/noke/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="/Content/noke/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="/Content/noke/js/inspinia.js"></script>
    <script src="/Content/noke/js/plugins/pace/pace.min.js"></script>

    
    <script src="~/Content/jqtree/tree.jquery.js"></script>

    
    <script>
        var fformmenu = function () {
            var thisobj = this;

            this.init = function () {

                var url = '/Home/GetApiDocList/?type=2000&level=2';
                $.getJSON(url, function (res) {
                    if (res) {
                        thisobj.menus = convertToTree(res);
                        var mhtml = bind(thisobj.menus, 1, thisobj.menuno);
                        $('#side-menu').append(mhtml);
                        $('#side-menu').metisMenu();

                    } else {
                        console.log('Get:' + res.Msg);
                    }
                }, 'json');


            };

            var bind = function (menus, level, menuno) {

                var mhtml = '', len = menus.length;

                for (var i = 0; i < len; i++) {
                    var m = menus[i], arrow = '', chtml = '', active = '', expend = '';

                    var icon = (m.icon) ? '<i class="fa fa-' + m.icon + '"></i>' : '';

                    if (thisobj.parentno == m.no.toString() || thisobj.menuno == m.no.toString()) {
                        active = ' class="active"';
                        expend = ' in';
                    }
                    if (m.childs && m.childs.length > 0) {
                        arrow = '<span class="fa arrow"></span>';
                        chtml = '<ul class="nav nav-second-level collapse' + expend + '">' + bind(m.childs, (level + 1), menuno) + '</ul>';
                    }
                    if (level == 1)
                        mhtml += '<li' + active + '><a href="' + m.url + '">' + icon + '<span class="nav-label">' + m.label + '</span>' + arrow + '</a>' + chtml + '</li>';
                    else
                        mhtml += '<li' + active + '><a href="' + m.url + '">' + icon + m.label + arrow + '</a>' + chtml + '</li>';
                }
                return mhtml;
            };
            this.parentno = getQueryString('parentno');
            this.menuno = getQueryString('no');


            this.menus = [];

            // ****转换成树形结构 【BEGIN】***********************************************
            var convertToTree = function (treeData) {
                var root = { "no": "0", "parentno": "0", "label": "Root", childs: [] }, len = treeData.length, temp = {}, key = '', list = [], item = null, parent = null;
                for (var level = 0; level < len; level++) {
                    list = treeData[level];
                    for (var i = 0; i < list.length; i++) {
                        item = list[i], item.icon = item.v1, item.url = item.v2;
                        parent = (level == 0) ? root : getParent(temp, item.parentno, root);
                        if (!parent || (parent.id == 0 && level != 0)) {
                            continue;
                        }
                        key = item.no;
                        temp[key] = (level == 0 ? '' : (temp[item.parentno] + '-')) + parent.childs.length;
                        item.childs = [];
                        parent.childs.push(item);
                    }
                }
                return root.childs;
            }
            var getParent = function (temp, pid, root) {
                if (temp[pid]) {
                    var ptemp = temp[pid].toString().split('-');
                    var parent = root;
                    $(ptemp).each(function (i, index) {
                        parent = parent.childs[parseInt(index)];
                    })
                    return parent;
                }
                return null;
            }
            // ****************** 【END】********************************

            function getQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }

            this.init();
        }
    </script>
    
    @RenderSection("scripts", required: false)
</body>
</html>
